def list2d(initializer, rows, columns):
  return [i[:] for i in [[initializer]*columns]*rows]

#dimensions are specified outer to inner, so ndlist(x, rows, cols) would result in ret[rows][cols]
def ndlist(initializer, *dimensions):
  ret = initializer
  for dimension in reversed(dimensions):
    ret = dimension*[ret]
  return [i[:] for i in ret]
